// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) definits fieldsfirst ansi space safe 
// Source File Name:   RobotView.java

package jones.gui;

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.geom.Line2D;
import java.util.Observable;
import java.util.Observer;
import javax.swing.event.MouseInputAdapter;
import jones.SimpleRobot;
import jones.World;
import jones.rigid.ConvexPolygon;

// Referenced classes of package jones.gui:
//            RigidBodyView, PolygonUtils, RobotProgrammer

public class RobotView extends RigidBodyView
    implements Observer
{

    private ConvexPolygon leftIRSweep = null;
    private ConvexPolygon rightIRSweep = null;
    private Line2D wheels = null;
    private boolean isLeftIROn = false;
    private boolean isRightIROn = false;
    private SimpleRobot simpleRobot = null;
    private World world = null;

    public RobotView(SimpleRobot simpleRobot, World world)
    {
        super(((jones.rigid.RigidBody) (simpleRobot)), world);
        leftIRSweep = new ConvexPolygon();
        rightIRSweep = new ConvexPolygon();
        wheels = ((Line2D) (new java.awt.geom.Line2D.Double()));
        isLeftIROn = false;
        isRightIROn = false;
        this.simpleRobot = simpleRobot;
        this.world = world;
        init();
    }

    private void init()
    {
        setOrientationHandleVisible(true);
        wheels.setLine(simpleRobot.getLeftWheelX(), simpleRobot.getLeftWheelY(), simpleRobot.getRightWheelX(), simpleRobot.getRightWheelY());
        simpleRobot.getLeftIRSweep(leftIRSweep);
        simpleRobot.getRightIRSweep(rightIRSweep);
        isLeftIROn = simpleRobot.isLeftIROn();
        isRightIROn = simpleRobot.isRightIROn();
        MouseInputAdapter mouseInputAdapter = ((MouseInputAdapter) (new MouseInputAdapter() {

            public void mouseClicked(MouseEvent e)
            {
                if (e.getClickCount() == 2)
                    new RobotProgrammer(simpleRobot);
            }

        }
));
        addMouseListener(((java.awt.event.MouseListener) (mouseInputAdapter)));
        addMouseMotionListener(((java.awt.event.MouseMotionListener) (mouseInputAdapter)));
    }

    public void update(Observable obs, Object obj)
    {
        super.update(obs, obj);
        synchronized (wheels)
        {
            wheels.setLine(simpleRobot.getLeftWheelX(), simpleRobot.getLeftWheelY(), simpleRobot.getRightWheelX(), simpleRobot.getRightWheelY());
        }
        synchronized (leftIRSweep)
        {
            simpleRobot.getLeftIRSweep(leftIRSweep);
        }
        synchronized (rightIRSweep)
        {
            simpleRobot.getRightIRSweep(rightIRSweep);
        }
        isLeftIROn = simpleRobot.isLeftIROn();
        isRightIROn = simpleRobot.isRightIROn();
        repaint();
    }

    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D)g;
        g2d.setColor(getForeground());
        synchronized (wheels)
        {
            g2d.draw(((java.awt.Shape) (wheels)));
        }
        if (isLeftIROn)
            g2d.setColor(Color.red);
        else
            g2d.setColor(Color.white);
        synchronized (leftIRSweep)
        {
            PolygonUtils.draw(((jones.rigid.Polygon) (leftIRSweep)), g2d);
        }
        if (isRightIROn)
            g2d.setColor(Color.red);
        else
            g2d.setColor(Color.white);
        synchronized (rightIRSweep)
        {
            PolygonUtils.draw(((jones.rigid.Polygon) (rightIRSweep)), g2d);
        }
    }

}
